package com.dein.music.controller;

import com.dein.music.model.Music;
import com.dein.music.model.MusicDislike;
import com.dein.music.service.MusicDislikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("musicDislike/")
public class MusicDislikeController {
    private MusicDislikeService musicDislikeService;

    @Autowired
    @Qualifier("musicDislikeService")
    public void setMusicDislikeService(MusicDislikeService musicDislikeService) {
        this.musicDislikeService = musicDislikeService;
    }

    @RequestMapping(value = "addDislikeMusic", method = RequestMethod.POST)
    public
    @ResponseBody
    Object addDislikeMusic(
            @RequestParam(value = "userId") Long userId,
            @RequestParam(value = "musicId")Long musicId) {
        Map<String, Object> map = new HashMap<String, Object>();

        boolean result = musicDislikeService.addDislikeMusic(userId, musicId);
        map.put("result",result);
        return map;
    }

    @RequestMapping(value = "deleteDislikeMusic", method = RequestMethod.POST)
    public
    @ResponseBody
    Object deleteDislikeMusic(
            @RequestParam(value = "userId") Long userId,
            @RequestParam(value = "musicId")Long musicId) {
        Map<String, Object> map = new HashMap<String, Object>();

        boolean result = musicDislikeService.deleteDislikeMusic(userId, musicId);
        map.put("result",result);
        return map;
    }

    @RequestMapping(value = "getDislikeMusicList", method = RequestMethod.POST)
    public
    @ResponseBody
    Object getDislikeMusicList(
            @RequestParam(value = "userId") Long userId,
            @RequestParam(value = "limit") Integer limit,
            @RequestParam(value = "start") Integer start) {
        List<Music> musicList = new ArrayList<Music>();
        musicList = musicDislikeService.getDislikeMusicList(userId,limit,start);
        return musicList;
    }

    @RequestMapping(value = "countDislikeMusic",method = RequestMethod.POST)
    public @ResponseBody
    Object countDislikeMusic(@RequestParam(value = "userId")Long userId){
        Integer count = musicDislikeService.countDislikeMusic(userId);
        return count;
    }
}
